package com.czh.wx.handler;

import com.czh.wx.constants.WxConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author caozaihui
 * @version 1.0
 * @since 2024/9/1 下午 9:22
 */
@Component
@Slf4j
public class SubscribeMsgHandler implements WxMsgHandler{
    @Override
    public WxChatMsgTypeEnum getMsgType() {
        return WxChatMsgTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String,String> requestMap) {
        log.info("用户触发关注事件");
        String toUserName = requestMap.get(WxConstant.XMLNODE_ToUserName);
        String fromUserName = requestMap.get(WxConstant.XMLNODE_FromUserName);
        String content ="欢迎关注辉哥公众号!获取验证码请回复[验证码]!";

        return "<xml>\n" +
                "  <ToUserName><![CDATA["+fromUserName+"]]></ToUserName>\n" +
                "  <FromUserName><![CDATA["+toUserName+"]]></FromUserName>\n" +
                "  <CreateTime>1348831860</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA["+content+"]]></Content>\n" +
                "  <MsgId>1234567890123456</MsgId>\n" +
                "  <MsgDataId>xxxx</MsgDataId>\n" +
                "  <Idx>xxxx</Idx>\n" +
                "</xml>\n" +
                "\n";
    }
}
